[#import "/framework/JGP.htm"  as JGP]
<!--
项目   jgp-cloud-parent
作者   LOUFEI [Gavin]
时间   2019-11-02
-->
[@JGP.head "编辑组结构"/]
[@JGP.body]
    <jgp-div _row="['40','*']" _runit="px" _aux="true">
        <div slot="1-1">
            <jgp-btn _fn="saveCallback" _form="form">保存</jgp-btn>
        </div>
        <jgp-panel slot="2-1">
            <jgp-form _id="form" _label_width="70px" _action="/sys/dd/param-api-ctl/save-group">
                <jgp-text _name="parent.label" _label="父级" _col="12" _readonly="true"></jgp-text>
                <jgp-text _name="value" _label="标识" _col="12" _readonly="true"></jgp-text>
                <jgp-text _name="label" _label="组名" _col="12" _required="true"></jgp-text>
                <jgp-text _name="value_aux" _submit="false" _label="标识后缀" _col="12" _required="true" _onchange="fixValue"></jgp-text>
                <jgp-area _name="description" _label="描述" _col="12"></jgp-area>
            </jgp-form>
        </jgp-panel>
    </jgp-div>
[/@JGP.body]

[@JGP.foot]
    <script>
        var id = ${id!'null'};
        var parentId = ${parentId!'null'};
        var parent;

        JGP.$onload(function () {
            initGroup();
        })

        function initGroup() {
            var form = JGP.form('form');
            if (id) {
                JGP.$post('/sys/dd/param-api-ctl/query-group-one', {id: id}, function (res) {
                    form.setData(res.data.group)
                })
            } else if (parentId !== null) {
                form.field('parentId', parentId);
                JGP.$post('/sys/dd/param-api-ctl/query-group-one', {id: parentId}, function (res) {
                    if(res.flag){
                        parent = res.data.group;
                    }
                    if(parent){
                        form.field('parent.label', parent.label);
                        form.field('value', parent.value);
                    }else{
                        form.field('parent.label','顶级');
                    }
                })
            }
        }

        function saveCallback(result) {
            if (result.back.flag) {
                JGP.$alert('保存成功')
                JGP.$close(true);
            }
        }

        function fixValue(args) {
            var form = JGP.form('form');
            var value = (parent ? (parent.value + '.') : '') + args.back
            form.field('value', value.toUpperCase());
        }
    </script>
[/@JGP.foot]